package com.teamwings.modules.list.controller;


import com.teamwings.common.vo.Result;
import com.teamwings.modules.list.entity.FormTableList;
import com.teamwings.modules.list.service.IFormTableListService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.system.vo.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 自动列表页面控制器
 * </p>
 *
 * @author admin
 * @since 2021-06-01
 */
@RestController
@Api(tags = "表单head")
@RequestMapping("/form/list")
@Slf4j
public class ListController {

    @Autowired
    private IFormTableListService formTableListService;

    /**
     * 保存表单列表
     */
    @ApiOperation(value = "添加或更新表单自动列表数据", notes = "添加或更新表单自动列表数据")
    @PostMapping(value = "/save")
    public Result<?> save(@RequestBody FormTableList vo) {
        // TODO
        //  sysuser为空
//        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
//        vo.setUpdateBy(sysUser.getUsername());
        formTableListService.saveOrUpdate(vo);
        return Result.OK("保存成功！", vo);
    }


    /**
     * 获取表单设计列表
     */
    @ApiOperation(value = "获取表单自动列表数据", notes = "获取表单自动列表数据")
    @GetMapping(value = "/queryById/{id}")
    public Result<?> queryById(@PathVariable("id") String id) {
        FormTableList record = formTableListService.getById(id);
        if (record == null) {
            return Result.error("没有找到数据！");
        } else {
            return Result.OK("查询成功！", record.getData());
        }
    }
}
